package org.elsfs.cloud.common.mybatis.ext.sql.support.condition;

import lombok.RequiredArgsConstructor;
import org.elsfs.cloud.common.util.lang.NamingCase;

/**
 * 字段子查询条件
 *
 */
@RequiredArgsConstructor
public class FieldSubQueryConditionItem implements ConditionItem {

    /**
     * 左边字段名称
     */
    private final String leftField;
    /**
     * 右边SQL
     */
    private final String rightSql;
    /**
     * 条件操作符
     */
    private final CompareOperator compareOperator;

    /**
     * 构建SQL片段
     *
     * @return SQL片段
     */
    @Override
    public String buildSqlFragment() {
        return String.format(
            "%s%s(%s)",
            NamingCase.toUnderlineCase(this.leftField),
            this.compareOperator.getOperator(),
            this.rightSql
        );
    }
}
